package com.warmlight.voicepacket.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.warmlight.voicepacket.R;
import com.warmlight.voicepacket.base.MBaseAdapter;
import com.warmlight.voicepacket.dbdata.DBFloatPlaylist;

import java.util.List;

/**
 * 悬浮框播单列表adapter
 * Created by jason on 2018/5/25.
 *
 */

public class FloatPlayListAdapter extends MBaseAdapter {

    public FloatPlayListAdapter(Context context, List<DBFloatPlaylist> list) {
        super(context, list);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;
        if (convertView != null) {
            holder = (ViewHolder) convertView.getTag();
        } else {
            convertView = View.inflate(mContext, R.layout.item_float_playlist, null);
            holder = new ViewHolder();
            holder.iv_float_playlist_image = (ImageView) convertView.findViewById(R.id.iv_float_playlist_image);
            holder.tv_float_playlist_title = (TextView) convertView.findViewById(R.id.tv_float_playlist_title);
            holder.tv_float_playlist_count = (TextView) convertView.findViewById(R.id.tv_float_playlist_count);
            convertView.setTag(holder);
        }
        RequestOptions options = new RequestOptions();
        options.dontAnimate();
        Glide.with(mContext).load(((DBFloatPlaylist)mList.get(position)).getList_img_path()).apply(options).into(holder.iv_float_playlist_image);
        holder.tv_float_playlist_title.setText(((DBFloatPlaylist)mList.get(position)).getList_name());
        holder.tv_float_playlist_count.setText(((DBFloatPlaylist)mList.get(position)).getList_count());

        return convertView;
    }

    private class ViewHolder {
        ImageView iv_float_playlist_image;
        TextView tv_float_playlist_title;
        TextView tv_float_playlist_count;
    }
}
